<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>学生信息修改</title>
<script type="text/javascript" src="js/jquery-3.2.0.js"></script>
<script type="text/javascript">
	var stuno = window.location.search.substring(1);
	var sname = "", sex = "", telephone = "", qq = "", wechat = "", fromcity = "", address = "", pass = "", enterdate = "", birthday = "", idcardpic = "";
	var gradeid = 1;
	$(function() {
		$.get("update.do", {stuno : stuno}, function(s) {
			$(":input[name=stuno]").val(s.stuno);
			$(":input[name=name]").val(s.sname);
			$(":radio[name=sex][value=" + s.sex + "]").prop("checked", true);
			$(":input[name=tel]").val(s.telephone);
			$(":input[name=qq]").val(s.qq);
			$(":input[name=wechat]").val(s.wechat);
			$(":input[name=enterdate]").val(s.enterdate);
			$(":input[name=fromcity]").val(s.fromcity);
			$(":input[name=birth]").val(s.birthday);
			$(":input[name=address]").val(s.address);
			$(":input[name=pass]").val(s.wechat);

			idcardpic = s.idcardpic;
			gradeid = s.gradeid;
			$("#img").attr("src", "images/" + idcardpic);
		});
		$.get("GradeAllAjaxServlet", {}, function(g) {
			var grade = $("select[name=gradeid]");
			$.each(g, function(i, d) {
				grade.append(new Option(d.gname, d.id));
			});
			grade.val(gradeid);
		});
		$("#save").click(function() {
			//$("form").serialize();
			var f = $("form")[0];//转换成dom对象

			var mydata = new FormData(f);
			$.ajax({
				url : "update2.do",
				type : "POST",
				data : mydata,
				contentType : false,
				processData : false,
				success : function(d) {
					alert(d);
					f.reset();
				}
			});
			$(location).attr("href","students.html");
			return false;
		});

	});
</script>
</head>
<body>
	<form action="#" method="post" enctype="multipart/form-data">
		<p>
			学号:<input type="text" name="stuno" readonly="readonly">
		</p>

		<p>
			姓名:<input type="text" name="name">
		</p>
		<p>
			性别: <input type="radio" name="sex" value="男">男 <input
				type="radio" name="sex" value="女">女 <input type="radio"
				name="sex" value="妖">妖
		</p>
		<p>
			电话:<input type="tel" name="tel">
		</p>
		<p>
			QQ:<input type="text" name="qq">
		</p>
		<p>
			微信:<input type="text" name="wechat">
		</p>
		<p>
			年级: <select name="gradeid"></select>
		</p>
		<p>
			入学日期:<input type="text" name="enterdate">
		</p>
		<p>
			来自城市:<input type="text" name="fromcity">
		</p>
		<p>
			出生日期:<input type="text" name="birth">
		</p>
		<p>
			家庭住址:<input type="text" name="address">
		</p>
		<p>
			密码:<input type="password" name="pass">
		</p>
		<p>
			身份证照片<input type="file" name="idpic" placeholder="更换照片"> <img
				id="img" alt="没有图片" height="200px" width="200px" />
		</p>
		<p>
			<input type="submit" value="提交修改" id="save">
		</p>
	</form>
</body>
</html>